<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="fnx" uri="http://java.sun.com/jsp/jstl/functionsx" %>
<%@ taglib prefix="s" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="f" uri="http://www.sctv.com/tags/form" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>
<!DOCTYPE html>
<html>
<head>
    <jsp:include page="/WEB-INF/views/head.jsp"/>
    <script type="text/javascript">
        $(function () {
            $("#sortHead").headSort();
        });

        function confirmDelete() {
            return confirm("<s:message code='confirmDelete'/>");
        }

        function optSingle(opt) {
            if (Cms.checkeds("ids") == 0) {
                alert("<s:message code='pleaseSelectRecord'/>");
                return false;
            }
            if (Cms.checkeds("ids") > 1) {
                alert("<s:message code='pleaseSelectOne'/>");
                return false;
            }
            var id = $("input[name='ids']:checkbox:checked").val();
            location.href = $(opt + id).attr("href");
        }

        function optDelete(form) {
            if (Cms.checkeds("ids") == 0) {
                alert("<s:message code='pleaseSelectRecord'/>");
                return false;
            }
            if (!confirmDelete()) {
                return false;
            }
            form.action = 'delete.do';
            form.submit();
            return true;
        }
    </script>
</head>
<body class="skin-blue content-body">
<jsp:include page="/WEB-INF/views/commons/show_message.jsp"/>
<div class="content-header">
    <h1><s:message code="publishPoint.management"/> - <s:message code="list"/>
        <small>(<s:message code="totalElements" arguments="${fn:length(list)}"/>)</small>
    </h1>
</div>
<div class="content">
    <div class="box box-primary">
        <div class="box-body table-responsive clearfix">
            <form method="post" class="pull-left">
                <tags:search_params/>
                <div class="btn-wrap">
                    <shiro:hasPermission name="core:publish_point:create">
                        <button class="btn btn-default" type="button"
                                onclick="location.href='create.do?${searchstring}';"><s:message code="create"/></button>
                    </shiro:hasPermission>
                    <shiro:hasPermission name="core:publish_point:copy">
                        <button class="btn btn-default" type="button" onclick="return optSingle('#copy_opt_');">
                            <s:message code="copy"/></button>
                    </shiro:hasPermission>
                    <shiro:hasPermission name="core:publish_point:edit">
                        <button class="btn btn-default" type="button" onclick="return optSingle('#edit_opt_');">
                            <s:message code="edit"/></button>
                    </shiro:hasPermission>
                </div>
                <%--<div class="btn-group">--%>
                <%--<shiro:hasPermission name="core:site:delete">--%>
                <%--<button class="btn btn-default" type="button" onclick="return optDelete(this.form);"><s:message code="delete"/></button>--%>
                <%--</shiro:hasPermission>--%>
                <%--</div>--%>
            </form>
            <form class="form-inline ls-search pull-left" action="list.do" method="get">
                <label><s:message code="publishPoint.name"/></label>
                <input class="form-control input-sm" type="text" name="search_CONTAIN_name"
                       value="${search_CONTAIN_name[0]}"/>
                <button class="btn btn-default btn-sm" type="submit"><s:message code="search"/></button>
            </form>
            <table id="pagedTable" class="table table-condensed table-bordered table-hover ls-tb form-inline">
                <thead id="sortHead" pagesort="<c:out value='${page_sort[0]}' />" pagedir="${page_sort_dir[0]}"
                       pageurl="list.do?page_sort={0}&page_sort_dir={1}&${searchstringnosort}">
                <tr class="ls_table_th">
                    <%--<th width="25"><input type="checkbox" onclick="Cms.check('ids',this.checked);"/></th>--%>
                    <th width="140"><s:message code="operate"/></th>
                    <th width="30" class="ls-th-sort"><span class="ls-sort" pagesort="id">ID</span></th>
                    <th class="ls-th-sort"><span class="ls-sort" pagesort="name"><s:message
                            code="publishPoint.name"/></span></th>
                    <th class="ls-th-sort"><span class="ls-sort" pagesort="storePath"><s:message
                            code="publishPoint.storePath"/></span></th>
                    <th class="ls-th-sort"><span class="ls-sort" pagesort="displayPath"><s:message
                            code="publishPoint.displayPath"/></span></th>
                    <th class="ls-th-sort"><span class="ls-sort" pagesort="method"><s:message
                            code="publishPoint.method"/></span></th>
                    <th class="ls-th-sort"><span class="ls-sort" pagesort="type"><s:message
                            code="publishPoint.type"/></span></th>
                </tr>
                </thead>
                <tbody>
                <c:forEach var="bean" varStatus="status" items="${list}">
                    <tr<shiro:hasPermission
                            name="core:site:edit"> ondblclick="location.href=$('#edit_opt_${bean.id}').attr('href');"</shiro:hasPermission>>
                            <%--&lt;%&ndash; 多选注释掉 &ndash;%&gt;
                          <td><input type="checkbox" name="ids" value="${bean.id}"/></td>--%>
                        <td align="center">
                            <shiro:hasPermission name="core:publish_point:copy">
                                <a id="copy_opt_${bean.id}" href="create.do?id=${bean.id}&${searchstring}"
                                   class="ls-opt"><s:message code="copy"/></a>
                            </shiro:hasPermission>
                            <shiro:hasPermission name="core:publish_point:edit">
                                <a id="edit_opt_${bean.id}"
                                   href="edit.do?id=${bean.id}&position=${status.index}&${searchstring}" class="ls-opt"><s:message
                                        code="edit"/></a>
                            </shiro:hasPermission>
                            <shiro:hasPermission name="core:publish_point:delete">
                                <c:choose>
                                    <c:when test="${bean.id==1}">
                                        <a class="ls-opt-disabled"><s:message code="delete"/></a>
                                    </c:when>
                                    <c:otherwise>
                                        <a href="delete.do?ids=${bean.id}&${searchstring}"
                                           onclick="return confirmDelete();" class="ls-opt"><s:message
                                                code="delete"/></a>
                                    </c:otherwise>
                                </c:choose>
                            </shiro:hasPermission>
                        </td>
                        <td><c:out value="${bean.id}"/></td>
                        <td><c:out value="${bean.name}"/></td>
                        <td><c:out value="${bean.storePath}"/></td>
                        <td><c:out value="${bean.displayPath}"/></td>
                        <td><s:message code="publishPoint.method.${bean.method}"/></td>
                        <td><s:message code="publishPoint.type.${bean.type}"/></td>
                    </tr>
                </c:forEach>
                </tbody>
            </table>
            <c:if test="${fn:length(list) le 0}">
                <div class="ls-norecord"><s:message code="recordNotFound"/></div>
            </c:if>
        </div>
    </div>
</div>
</body>
</html>